<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Download extends Controller_Main{

	public function action_index(){
		$post = $this->request->post();
		if (isset($post['submit'])) {
			
			$text = $post['text'];
			
			if (!empty($_FILES['picture']['tmp_name'][0])) {
				foreach($_FILES['picture'] as $param => $value) {
					$i = 0;
					foreach($value as $item) {
						$images[$i][$param] = $item;
						$i++;
					}
				}
				
				if(count($images) > 0){
					Model::factory('Images')->add_images($images[0],$text);			
				}
			}
			
			$this->request->redirect('/');		
		}
		$content = View::factory('download');
		$this->template->content = $content;
	}
} 
